#ifndef _RECORDSET_H_
#define _RECORDSET_H_

#include "stdafx.h"
#include <db/idatabase.h>

class CRecordSet : public IRecordSet, public CUnknownImp
{
public:
    CRecordSet(sqlite3_stmt* pStmt3);
    virtual ~CRecordSet(void);

public:
    BEGIN_STDCOM_MAP
    STDCOM_INTERFACE_ENTRY(IRecordSet)
    END_STDCOM_MAP

public:
    std_method_(UINT, Next)();
    std_method_(UINT, Previous)();
    std_method_(UINT, First)();
    std_method_(UINT, Last)();
    std_method_(uint64, GetCount)() { return m_nRowCount; }
    std_method_(ULONG, GetFieldCount)() { return m_nFieldCount; }
    std_method(GetInt)(LPCSTR lpszName, INT& nValue);
    std_method(GetInt64)(LPCSTR lpszName, int64& nValue);
    std_method(GetUInt)(LPCSTR lpszName, UINT& nValue);
    std_method(GetUInt64)(LPCSTR lpszName, uint64& nValue);
    std_method(GetFloat)(LPCSTR lpszName, float& fValue);
    std_method(GetDouble)(LPCSTR lpszName, double& dValue);
    std_method_(LPCSTR, GetString)(LPCSTR lpszName);
    std_method_(const unsigned char*, GetBlob)(LPCSTR lpszName);
    std_method(GetInt)(unsigned int nIndex, INT& nValue);
    std_method(GetInt64)(unsigned int nIndex, int64& nValue);
    std_method(GetUInt)(unsigned int nIndex, UINT& nValue);
    std_method(GetUInt64)(unsigned int nIndex, uint64& nValue);
    std_method(GetFloat)(unsigned int nIndex, float& fValue);
    std_method(GetDouble)(unsigned int nIndex, double& dValue);
    std_method_(LPCSTR, GetString)(unsigned int nIndex);
    std_method_(const unsigned char*, GetBlob)(unsigned int nIndex);

public:
    static HRESULT CreateInstance(sqlite3_stmt* pStmt, IRecordSet** ppRecordSet);

private:
    unsigned int GetFieldIndex(LPCSTR lpszName);

private:
    ULONG m_nRowPosition;
    ULONG m_nRowCount;
    ULONG m_nFieldCount;

    typedef std::map<unsigned int, std::string> record;
    std::vector<record> m_vRecordList;
    std::map<unsigned int, std::string> m_Record;
    std::map<std::string, unsigned int> m_vFieldIndex;
};

#endif
